{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>酒店详情</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">酒店名称</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="title" value="{$system.title}" lay-verify="required" placeholder="请输入酒店名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">酒店电话</label>
            <div class="layui-input-4">
                <input type="text"  name="phone" value="{$system.phone}" lay-verify="phone" placeholder="请输入酒店电话" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付方式</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="pay_type" value="{$system.pay_type}" lay-verify="required" placeholder="请输入支付方式，多个用|隔开" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">房间佣金</label>
            <div class="layui-input-4">
                <input type="text" maxlength="11" name="room_com" value="{$system.room_com}" lay-verify="phone" placeholder="请输入房间佣金比例单位（%）" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">用户订房给推荐人返还佣金比例</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">次卡佣金</label>
            <div class="layui-input-4">
                <input type="text" maxlength="11" name="second_com" value="{$system.second_com}" lay-verify="phone" placeholder="请输入次卡佣金比例单位（%）" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">用户购买次卡推荐人返还佣金比例</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">储值卡佣金</label>
            <div class="layui-input-4">
                <input type="text" maxlength="11" name="recharge_com" value="{$system.recharge_com}" lay-verify="phone" placeholder="请输入储值卡佣金比例单位（%）" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">用户充值给推荐人返还佣金比例</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">钟点房预订时间</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="start_time" value="{$system.start_time}" lay-verify="required" placeholder="开放预订时间(h:m:s)" class="layui-input">
            </div>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="end_time" value="{$system.end_time}" lay-verify="required" placeholder="停止预订时间(h:m:s)" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">钟点房预订开放时间，第一个为开始预订时间，第二个为结束预订时间，比如8点~22点填写8 22</div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">酒店地址</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="address" value="{$system.address}" lay-verify="required" placeholder="酒店地址" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">酒店介绍</label>
            <div class="layui-input-4" style="width:80%;height:350px;">
               <script id="description" name="description" lay-verify="required" type="text/plain" style="width:80%; height:200px;">{$system.description}</script>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">酒店banner图</label>
            <input type="hidden" lay-verify="required" name="banner" id="logo2" value="{$system.banner}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="logoBtn2"><i class="icon icon-upload3"></i>点击上传</button>
                    <button type="button" class="layui-btn layui-btn-primary" id="logoBtn3"><i class="icon icon-upload3"></i>清空重新上传</button>
                    <div class="layui-upload-list" id="SLogo2">
                        <!-- <img class="layui-upload-img" src="{$system.banner}" > -->
                        <p id="demoText2"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">配套设施</label>
            <div class="layui-input-block">
                {volist name='list' id='vo'}
                <input type="checkbox" lay-verify="required" name="support_id" title="{$vo.title}" value="{$vo.id}" {if $vo.sel}checked{/if}>
                {/volist}
              
                
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">交通服务</label>
            <div class="layui-input-4" style="width:80%;height:350px;">
               <script id="traffic" lay-verify="required" name="traffic"  type="text/plain" style="width:80%; height:200px;">{$system.traffic}</script>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商务服务</label>
            <div class="layui-input-4" style="width:80%;height:350px;">
               <script id="business_services" lay-verify="required" name="business_services"  type="text/plain" style="width:80%; height:200px;">{$system.business_services}</script>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submit" lay-submit="" lay-filter="sys">{:lang('submit')}</button>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
    
    let img_url =$('#logo2').val().split(',')
    if(img_url.length >0){
        let text = ''
        for(let i=0; i<img_url.length;i++){
            text+=`<img class="layui-upload-img" src="${img_url[i]}">`
        }
        $('#SLogo2').html(text)
    }
    
    var ue = UE.getEditor('description');
    ue.ready(function(){
        ue.addListener("contentChange", function () {
	    $('#description').val(ue.getContent());
    });
    })
   
    var traffic = UE.getEditor('traffic');
    traffic.ready(function(){
        traffic.addListener("contentChange", function () {
	    $('#traffic').val(ue.getContent());
    });
    })
    
    var business_services = UE.getEditor('business_services');
    business_services.ready(function(){
        business_services.addListener("contentChange", function () {
	    $('#business_services').val(ue.getContent());
    });
    })
    $('#logoBtn3').click(function(){
        img_url=[]
        $('#logo2').val(img_url)
        $('#SLogo2 img').remove()
        
    })
    layui.use(['form', 'layer','upload'], function () {
        var form = layui.form,layer = layui.layer,upload = layui.upload,$ = layui.jquery;
		form.verify({
            title: function(value){  
				if(value == ''){  
					return '请输入酒店名称！';  
				}  
            },
            phone:function(value){
                if(value==''){
                    return '请输入酒店联系电话';
                }
            },
            pay_type:function(value){
                if(value==''){
                    return '请输入酒店支付方式'
                }
            },
            address:function(value){
                if(value==''){
                    return '请输入酒店地址'
                }
            },
            description:function(value){
                if(value==''){
                    return '请输入酒店介绍'
                }
            },
			banner: function(value){  
				if(value == ''){  
					return '请添加登录图！';  
				}  
            },
            support_id:function(value){
                console.log('supp:',value)
            }			
        });
		//普通图片上传    后台登录页背景图片
        var uploadInst2 = upload.render({
			elem: '#logoBtn2'
            ,url: '{:url("UpFiles/upload")}',
            accept:'images',
            acceptMime: 'image/*'
            ,size:0
            ,multiple:true
            ,number:6
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                img_url = $('#logo2').val().split(',')
                obj.preview(function(index, file, result){
                    let img = document.createElement('img')
                    img.src = result
                    img.className = 'layui-upload-img'
                    $('#SLogo2').append(img); //图片链接（base64）
                });
            }
            ,done: function(res){
                    if(res.errorCode==8888){
                        if(img_url.leng<=1 && !img_url[0]){
                            $('#logo2').val(res.url);
                        }else{
                            img_url.push(res.url)
                            $('#logo2').val(img_url.join(','));
						    layer.msg(res.msg,{time:1000,icon:1});
                        }
                    }else{
						$('#SLogo2').attr('src','');
                        layer.msg(res.msg,{time:2000,icon:2});
                    }
                }
        });
        //提交监听
        form.on('submit(sys)', function (data) {
            $("#submit").attr({ disabled: "disabled" });
            let arr = []
            $("input:checkbox[name='support_id']:checked").each(function(i){
                arr[i] = $(this).val();
            });
            data.field.support_id = arr.toString()
            loading =layer.load(1, {shade: [0.1,'#fff']});
           
            let banner = data.field.banner.split(',')
            if(banner.length>0&&banner[0]==''){
                banner.shift()
            }
            data.field.banner = banner.join()
            $.post("{:url('hotel/index')}",data.field,function(res){
                layer.close(loading);
                if(res.errorCode == 8888){
                    layer.msg(res.msg,{icon: 1, time: 1000},function(){
                        location.href = res.url;
                    });
                }else{
					$("#submit").removeAttr("disabled");
                    layer.msg(res.msg,{icon: 2, time: 1000});
                }
            });
        })
    })
	

</script>


</body>
</html>